import json
import yaml    #pip install pyyaml 
 
def toDict(dictStr):
    '''通用方法。解析字符串形式的字典
        dictStr = "{'Name':'mt7', 'IP':'192.168.31.7:8080'}"
        字典转换字符串 s =  json.dumps( {"a" : 1, "b" : 2, "c" : 3} )
        字符串转换字典  dct =  yaml.load( '{"a" : 1, "b" : 2, "c" : 3}' )
    '''        
    items = yaml.load(dictStr, Loader=yaml.FullLoader)
    items = items if isinstance(items, dict) else None
    return items